package com.aerozhonghuan.logisticsmall.utils;

public class To16 {

    private final static byte[] hex = "0123456789ABCDEF".getBytes();

    public static String bytesToHexString(byte[] bytes) {
        byte[] buff = new byte[2 * bytes.length];
        for (int i = 0, length = bytes.length; i < length; i++) {
            buff[2 * i] = hex[(bytes[i] >> 4) & 0x0f];
            buff[2 * i + 1] = hex[bytes[i] & 0x0f];
        }
        return new String(buff);
    }

    public static String decodeHexString(String src) {
        int l = src.length() / 2;
        byte[] ret = new byte[l];
        for (int i = 0; i < l; i++) {
            ret[i] = (byte) Integer
                    .valueOf(src.substring(i * 2, i * 2 + 2), 16).byteValue();
        }
        return new String(ret);
    }

}
